class ScrollerController extends PlayerController;

var vector PlayerMouse;
var float LastHUDSizeX;
var float LastHUDSizeY;
var vector sightStart, sightEnd;
var float targetAngle;
var ScrollPawnController MovingPawnController;
const RadianToURot   = 10430.377930;

function Possess(Pawn aPawn)
{
    local vector OffsetVector, OffsetLocation;

    OffsetVector = vect(0, 0, 0);
    //OffsetVector.Y = 0.5 * PlayerController(aPlayer).CameraDist * Default.CollisionRadius; == 99
    OffsetVector.Y = 99.00; //above line hardcoded
    OffsetLocation = self.location + OffsetVector;

    if(MovingPawnController == none)
        MovingPawnController = Spawn(class'SideScroller.ScrollPawnController',,,OffsetLocation);
    if(MovingPawnController.Pawn == none)
        MovingPawnController.Pawn = Spawn(class'SideScroller.ScrollMovingPawn',,,OffsetLocation);
    MovingPawnController.Possess(MovingPawnController.Pawn);


    Super.Possess(aPawn);
}



state PlayerWalking
{

    function PlayerMove( float DeltaTime )
    {
        local vector X,Y,Z, NewAccel;
        local eDoubleClickDir DoubleClickMove;
        local rotator OldRotation, ViewRotation;
        local bool  bSaveJump;


        local vector MouseV, ScreenV;

        // get the new mouse position offset
        MouseV.X = DeltaTime * aMouseX / (InputClass.default.MouseSensitivity * DesiredFOV * 0.01111);
        MouseV.Y = DeltaTime * aMouseY / (InputClass.default.MouseSensitivity * DesiredFOV * -0.01111);

        // update mouse position
        PlayerMouse += MouseV;

        // convert mouse position to screen coords, but only if we have good screen sizes
        if ((LastHUDSizeX > 0) && (LastHUDSizeY > 0))
        {
           ScreenV.X = PlayerMouse.X + LastHUDSizeX * 0.5;
           ScreenV.Y = PlayerMouse.Y + LastHUDSizeY * 0.5;
           //log("targetAngle = "$targetAngle);
         // here is where you would use the screen coords to do a trace or check HUD elements


        }

        targetAngle = targetAngle * RadianToURot;
        targetAngle = 16384-targetAngle;
        //log(targetAngle);
        MovingPawnController.Pawn.SetViewPitch(-targetAngle);
        log(MovingPawnController.Pawn.Rotation.yaw);

        if( Pawn == None )
        {
            GotoState('Dead'); // this was causing instant respawns in mp games
            return;
        }

        GetAxes(MovingPawnController.Pawn.Rotation,X,Y,Z);


        // Update acceleration.
        NewAccel = aForward*-Y + aStrafe*X;
//        NewAccel = aForward*X + aStrafe*Y;
        NewAccel.Z = 0;
        if ( VSize(NewAccel) < 1.0 )
            NewAccel = vect(0,0,0);
//        DoubleClickMove = PlayerInput.CheckForDoubleClickMove(1.1*DeltaTime/Level.TimeDilation);

//        GroundPitch = 0;
//        ViewRotation = Rotation;
//        if ( PawnToMove.Physics == PHYS_Walking )
//        {
//            // tell pawn about any direction changes to give it a chance to play appropriate animation
//            //if walking, look up/down stairs - unless player is rotating view
//             if ( (bLook == 0)
//                && (((PawnToMove.Acceleration != Vect(0,0,0)) && bSnapToLevel) || !bKeyboardLook) )
//            {
//                if ( bLookUpStairs || bSnapToLevel )
//                {
//                    GroundPitch = FindStairRotation(deltaTime);
//                    ViewRotation.Pitch = GroundPitch;
//                }
//                else if ( bCenterView )
//                {
//                    ViewRotation.Pitch = ViewRotation.Pitch & 65535;
//                    if (ViewRotation.Pitch > 32768)
//                        ViewRotation.Pitch -= 65536;
//                    ViewRotation.Pitch = ViewRotation.Pitch * (1 - 12 * FMin(0.0833, deltaTime));
//                    if ( (Abs(ViewRotation.Pitch) < 250) && (ViewRotation.Pitch < 100) )
//                        ViewRotation.Pitch = -249;
//                }
//            }
//        }
//        else
//        {
//            if ( !bKeyboardLook && (bLook == 0) && bCenterView )
//            {
//                ViewRotation.Pitch = ViewRotation.Pitch & 65535;
//                if (ViewRotation.Pitch > 32768)
//                    ViewRotation.Pitch -= 65536;
//                ViewRotation.Pitch = ViewRotation.Pitch * (1 - 12 * FMin(0.0833, deltaTime));
//                if ( (Abs(ViewRotation.Pitch) < 250) && (ViewRotation.Pitch < 100) )
//                    ViewRotation.Pitch = -249;
//            }
//        }
//        PawnToMove.CheckBob(DeltaTime, Y);
//
//        // Update rotation.
////        SetRotation(ViewRotation);
////        OldRotation = Rotation;
////        UpdateRotation(DeltaTime, 1);
//		bDoubleJump = false;
//
//        if ( bPressedJump && PawnToMove.CannotJumpNow() )
//        {
//            bSaveJump = true;
//            bPressedJump = false;
//        }
//        else
//            bSaveJump = false;

        if ( Role < ROLE_Authority ) // then save this move and replicate it
            ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
        else
        {
            ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
        }
        bPressedJump = bSaveJump;
    }

    function ProcessMove ( float DeltaTime, vector newAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
        MovingPawnController.ProcessMove(DeltaTime, newAccel, DoubleClickMove, DeltaRot);
    }
}


defaultproperties
{

}
